package com.example.demo0710;

import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "MainActivity_TAG";
    private ImageView mIbVoice;
    private ImageButton mIbVolume;
    private LinearLayout mLlText;
    private ImageButton mIbCall;
    private Animation shake;
    private ValueAnimator load;
    private boolean flag = true;
    private String[] scoreText = {"Video calling", "Video calling.", "Video calling..", "Video calling..."};
    /**
     * Video calling...
     */
    private TextView mTvCall;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        startAnim();
    }

    private void startAnim() {
        shake = AnimationUtils.loadAnimation(this, R.anim.shake);
        load = ValueAnimator.ofInt(0, 4).setDuration(1000);
        load.setRepeatCount(ValueAnimator.INFINITE);
        load.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int i = (int) animation.getAnimatedValue();
                mTvCall.setText(scoreText[i % scoreText.length]);
            }
        });
        mIbCall.startAnimation(shake);
        load.start();
    }

    private void initView() {
        mIbVoice = (ImageView) findViewById(R.id.ib_voice);
        mIbVoice.setOnClickListener(this);
        mIbVolume = (ImageButton) findViewById(R.id.ib_volume);
        mIbVolume.setOnClickListener(this);
        mLlText = (LinearLayout) findViewById(R.id.ll_text);
        mIbCall = (ImageButton) findViewById(R.id.ib_call);
        mIbCall.setOnClickListener(this);
        mTvCall = (TextView) findViewById(R.id.tv_call);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.ib_voice:
                Log.i(TAG, "点击ib_voice");
                if (!flag) {
                    Log.i(TAG, "ib_voice true");
                    mIbVoice.setSelected(false);
                    flag = true;
                } else {
                    Log.i(TAG, "ib_voice false");
                    mIbVoice.setSelected(true);
                    flag = false;
                }

                break;
            case R.id.ib_volume:
                break;
            case R.id.ib_call:
                shake.cancel();
                startActivity(new Intent(this, SeeKBarActivity.class));
                break;
        }
    }
}